package edu.gatech.cs2340.OregonTrail.EventSystem;

import java.util.Iterator;
import java.util.Map;

import edu.gatech.cs2340.OregonTrail.Item;
import edu.gatech.cs2340.OregonTrail.ShopPanel;


public class PlayerInventoryModifiedEvent extends ActorEvent{
	Map<Item, Integer> itemAmounts;
	Object source;
	
	public PlayerInventoryModifiedEvent(Object source, Map<Item, Integer> itemAmounts){
		this.source = source;
		this.itemAmounts = itemAmounts;
	}
	
	public Object getSource() {
		return source;
	}
	
	public int getTotalWeight(){
		int weight = 0;
		Iterator<Item> it = itemAmounts.keySet().iterator();
		Item nextItem = null;
		while(it.hasNext()){
			nextItem = it.next();
			weight += nextItem.getWeight() * itemAmounts.get(nextItem);
		}
		return weight;
	}
	
	//I'm going to have to be changed to properly account for regional prices. A bitch, I know
	public int getTotalCost(){
		int cost = 0;
		Iterator<Item> it = itemAmounts.keySet().iterator();
		Item nextItem = null;
		while(it.hasNext()){
			nextItem = it.next();
			cost += nextItem.getBaseCost() * itemAmounts.get(nextItem);
		}
		
		return cost;
	}

	/**
	 * @return the itemAmounts
	 */
	public Map<Item, Integer> getItemAmounts() {
		return itemAmounts;
	}
	
	public void updatePlayerInfo(int newFunds, int newWeight, Map<Item, Integer> playerStock){
		((ShopPanel) source).updatePlayerInfo(newFunds, newWeight, playerStock);
	}
}
